package com.example.admin.controller;

import com.example.admin.result.ResponseResult;
import com.example.admin.service.ServerSentEventsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@RestController
@RequestMapping("/sse")
public class ServerSentEventsController {

    @Autowired
    ServerSentEventsService serverSentEventsService;

    @GetMapping(value = "/connect", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public SseEmitter connect() {
        return serverSentEventsService.createEmitter();
    }

    @GetMapping("/cole")
    public ResponseResult<Object> close(@RequestParam String clientID) {
        return serverSentEventsService.close(clientID);
    }

    @PostMapping("/send")
    public ResponseResult<Object> send() {
        return serverSentEventsService.send();
    }

}
